<template>
  <el-container>
    <el-form  :model="hyxxbData"  label-position="right" label-width="100px" style="width:100%;text-align: center" ref="hyxxb" >
      <h3 :labelName="labelName">{{labelName}}</h3>
      <el-form-item label="物质编码" prop="1">
        <el-input v-model="hyxxbData.baseinfoWzbm"  :disabled="true"  ></el-input>
      </el-form-item>
      <el-form-item label="参数单位"  prop="3">
        <el-input v-model="hyxxbData.unit" placeholder="请输入内容" ></el-input>
      </el-form-item>
      <el-form-item label="值" prop="4">
        <el-input v-model="hyxxbData.value"   placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item label="时间" prop="5">
        <el-input v-model="hyxxbData.time" placeholder="请输入内容" ></el-input>
      </el-form-item>
      <el-form-item label="数据来源" prop="6">
        <el-input v-model="hyxxbData.source" placeholder="请输入内容" ></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="7">
        <el-input v-model="hyxxbData.remark" placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item prop="11">
        <el-button type="primary" style="margin-top: 12px;" @click="method" :btName="btName">{{btName}}</el-button>
      </el-form-item>
    </el-form>
  </el-container>
</template>

<script>
  export default {
    name: "Hyxxb",
    props: {
      elementId: {
        type: String,
        default: ''
      },
      perms: '',
      labelName:'',
      btName:'',
      showdata:{}
    },
    data() {
      return {
        hyxxbData: {
          'id': '',
          'baseinfoWzbm': '',
          'attribute':'',
          'source': '',
          'remark': '',
          'flag': '',
          'lastid': '',
          'unit':'',
          'value':'',
          'time':''
        },
        findParams:{
          elementId:'',
          labelName:'',
          flag:''
        },
        addParams:{
          labelName:''
        }
      }
    },
    watch: {
      elementId(value) {
      }
    },
    mounted() {
      console.log('elementID:' + this.elementId)
      console.log(this.perms)
      this.$nextTick(()=>{
        this.$refs['hyxxb'].resetFields()}
      )
      this.hyxxbData=this.showdata
    },
    methods: {
      queryElement: function () {
        console.log(this.labelName)
        this.findParams.elementId = this.elementId
        this.findParams.labelName = this.labelName
        this.findParams.flag = 1
        console.log(this.findParams.flag)
        this.$api.addrecord.findByIdAndFlagInHyxxb(this.findParams).then(res => {
          this.hyxxbData = res.data[0]
        })

      },
      modifyId: function () {
        this.hyxxbData.id = this.perms + Date.now()
      },
      modifyAuthority: function () {
        if (this.perms === 'admin') {
          this.hyxxbData.flag = 1
        } else {
          if (this.btName === "新增") {
            this.hyxxbData.flag = 0
          } else {
            this.hyxxbData.flag = 2
          }
        }
      },
      save: function () {
        this.modifyAuthority()
        this.addParams.labelName = this.labelName
        if (this.btName === "新增") {
          this.modifyId()
          this.$api.addrecord.addRecordInHyxxb(this.hyxxbData, this.addParams).then(res => {
            alert("新增成功！")
          })
        } else {
          this.hyxxbData.lastid = this.hyxxbData.id
          this.modifyId()
          this.$api.addrecord.addRecordInHyxxb(this.hyxxbData, this.addParams).then(res => {
            alert("纠错成功！待审核")
          })
        }
      },
      update:function () {
        this.modifyAuthority()
        this.$api.addrecord.updateInHyxxb(this.hyxxbData).then(res => {
          alert("更新成功！")
        })
        //删除操作
      },
      method:function () {
        if(this.btName==="更新"){
          this.update()
        }else {
          this.save()
        }
      }
    }
  }
</script>

<style scoped>

</style>
